package com.marsoft.test.exception;

import com.marsoft.test.utils.ResultMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理器
 *
 */
@RestControllerAdvice
public class DefinitionExceptionHandler {
	private Logger logger = LoggerFactory.getLogger(getClass());

	/**
	 * 处理自定义异常
	 */
	@ExceptionHandler(DefinitionException.class)
    public ResultMap handleDefinitionException(DefinitionException e){

        logger.error(e.getMessage(), e);

        return ResultMap.error(e.getCode(), e.getMsg());
}

    @ExceptionHandler(java.lang.Exception.class)
    public ResultMap handleException(java.lang.Exception e){
        logger.error(e.getMessage(), e);
        return ResultMap.error();
    }

}
